<script setup lang="ts">
import { $t } from '@/locales';

defineOptions({
  name: 'DictSearch'
});

interface DictSearchParams {
  current?: number;
  size?: number;
  dictType?: string;
  itemCode?: string;
  itemName?: string;
}

const model = defineModel<DictSearchParams>('model', { required: true });

defineProps<{
  dictTypes: string[];
}>();

interface Emits {
  (e: 'reset'): void;
  (e: 'search'): void;
}

const emit = defineEmits<Emits>();

function reset() {
  emit('reset');
}

function search() {
  emit('search');
}
</script>

<template>
  <ACard :bordered="false" class="card-wrapper">
    <AForm :model="model" :label-width="80">
      <ARow :gutter="[16, 16]" wrap>
        <ACol :span="24" :md="12" :lg="6">
          <AFormItem label="字典类型" name="dictType" class="m-0">
            <ASelect v-model:value="model.dictType" placeholder="字典类型" allow-clear style="width: 100%">
              <ASelectOption v-for="type in dictTypes" :key="type" :value="type">
                {{ type }}
              </ASelectOption>
            </ASelect>
          </AFormItem>
        </ACol>
        <ACol :span="24" :md="12" :lg="6">
          <AFormItem label="字典编码" name="itemCode" class="m-0">
            <AInput v-model:value="model.itemCode" placeholder="字典编码" allow-clear />
          </AFormItem>
        </ACol>
        <ACol :span="24" :md="12" :lg="6">
          <AFormItem label="映射名称" name="itemName" class="m-0">
            <AInput v-model:value="model.itemName" placeholder="映射名称" allow-clear />
          </AFormItem>
        </ACol>
        <ACol :span="24" :md="12" :lg="6">
          <AFormItem class="m-0">
            <div class="w-full flex-y-center justify-end gap-12px">
              <AButton @click="reset">
                <template #icon>
                  <icon-ic-round-refresh class="align-sub text-icon" />
                </template>
                <span class="ml-8px">{{ $t('common.reset') }}</span>
              </AButton>
              <AButton type="primary" ghost @click="search">
                <template #icon>
                  <icon-ic-round-search class="align-sub text-icon" />
                </template>
                <span class="ml-8px">{{ $t('common.search') }}</span>
              </AButton>
            </div>
          </AFormItem>
        </ACol>
      </ARow>
    </AForm>
  </ACard>
</template>

<style scoped></style>
